
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        车辆添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
    <link rel="icon" th:href="@{/images/favicon.ico}" type="image/x-icon"/>
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}"></script>
    <link rel="stylesheet" th:href="@{/css/index.css}">


</head>
<body>
<div id="app">
    <div class="x-nav" style="margin-left: 20%">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>小区管理</cite></a>
              <a><cite>{{title}}</cite></a>
            </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body" style="margin-left: 20%">
        <el-form :model="car" :rules="rules" ref="carFormRef" label-width="120px" class="demo-ruleForm">
            <el-form-item label="所属成员" prop="ownerName">
                <el-input v-model="car.ownerName"></el-input>
            </el-form-item>
            <el-form-item label="车辆颜色" prop="color">
                <el-input v-model="car.color"></el-input>
            </el-form-item>
            <el-form-item label="车牌号" prop="carNumber">
                <el-input v-model="car.carNumber"></el-input>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
                <el-input v-model="car.remark"></el-input>
            </el-form-item>
            <el-form-item label="创建时间" prop="createTime">
                <el-input v-model="car.createTime"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="save()" style="text-align: center">保存</el-button>
                <el-button @click="clearAll()" style="text-align: center">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</div>

<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/x-layui.js}" charset="utf-8"></script>
<!--导入Vue依赖包-->
<script th:src="@{/js/vue.js}" charset="utf-8"></script>
<!-- 引入Element组件库 -->
<script th:src="@{/js/index.js}"></script>
<!--导入Axios依赖包-->
<script th:src="@{/js/axios.js}" charset="utf-8"></script>
<script type="text/javascript">

    var app = new Vue({
        el: "#app",
        data: {
            title: "添加车辆",
            communityList:[],

            car: { carId: ""},
            fileList: [],
            rules: {
                ownerName: [
                    {required: true, message: '请输入所属成员', trigger: 'blur'},
                    {max: 50, message: '长度小于50个字符', trigger: 'blur'}
                ],
                color: [
                    {required: true, message: '请输入车辆颜色', trigger: 'blur'},
                    {min: 2, max: 3, message: '长度必须大于11、小于20个字符', trigger: 'blur'}
                ],
                carNumber: [
                    {required: true, message: '请输入车牌号', trigger: 'blur'}
                ],
                remark: [
                    {required: true, message: '请输入车辆备注', trigger: 'blur'}
                ],
                createTime: [
                    {required: true, message: '请输入创建时间', trigger: 'blur'}
                ]
            }
        },
        methods: {
            selectChange(){
                axios.post("/community/find", this.searchMap).then((res) => {
                    console.log(res)
                    app.communityList = res.data.data;
                });
            },
            findById() {
                axios.get("/car/findById?carId=" + this.car.carId).then((res) => {
                    this.car = res.data.data;

                });
            },

            //表达重置
            clearAll() {
                this.$refs.carFormRef.resetFields();
                if (this.fileList.length > 0) {
                    this.handleRemove();
                }
            },
            save() {
                var method = "";
                if (this.car.carId != null) {
                    method = "update"
                } else {
                    method = "add"
                }
                axios.post("/car/" + method, this.car).then((res) => {
                    if (res.data.flag) {
                        this.$message({
                            message: res.data.message,
                            type: 'success'

                        });

                    }

                });
                // this.findById();
            },

            getQueryString(name) {
                let reg = `(^|&)${name}=([^&]*)(&|$)`
                let r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
        },
        created: function () {
            layui.use(['element', 'layer', 'form'], function () {
                $ = layui.jquery;//jquery
                lement = layui.element();//面包导航
                layer = layui.layer;//弹出层
                form = layui.form();
                okLoading.close($);
            });
            //获取父页面传递参数，小区ID
            this.car.carId = this.getQueryString("carId");
            //根据小区ID获取小区对象，进行数据回显
            if (this.car.carId != null && this.car.carId != '') {
                this.title = "修改车辆";
                this.selectChange();
                this.findById();
            }

        }
    });
</script>

</body>
</html>